<?php

namespace App\Common;

use App\Common\ConstCode\ResponseConstCode;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\Di\Annotation\Inject;

class Response
{
    /**
     * @Inject
     * @var ResponseInterface
     */
    private $response;

    /**
     * @param array $data
     * @param string $message
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function success(array $data = [], string $message = 'success')
    {
        $code = ResponseConstCode::SUCCESS_CODE;
        return $this->response->json(compact('code', 'data', 'message'));
    }

    /**
     * @param array $data
     * @param string $message
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function fail(array $data = [], string $message = 'error')
    {
        $code = ResponseConstCode::FAIL_CODE;
        return $this->response->json(compact('code', 'data', 'message'));
    }

    /**
     * @param array $data
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function json(array $data)
    {
        return $this->response->json($data);
    }
}